/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package scheduler;

/**
 *
 * @author Musikero
 */
public class Ciphering {
    private final String ALPHABET = "1234567890";
     public String encrypt(String plainText,int shiftKey){
           plainText = plainText.toLowerCase();
           String cipherText="";
           for(int i=0;i<plainText.length();i++){
                int charPosition = ALPHABET.indexOf(plainText.charAt(i));
                int keyVal = (shiftKey+charPosition)%10;
                char replaceVal = this.ALPHABET.charAt(keyVal);
                cipherText += replaceVal;
           }
           return cipherText;
     }
     
     public String decrypt(String cipherText, int shiftKey){
           cipherText = cipherText.toLowerCase();
           String plainText="";
           for(int i=0;i<cipherText.length();i++){
                int charPosition = this.ALPHABET.indexOf(cipherText.charAt(i));
                int keyVal = (charPosition-shiftKey)%10;
                
                if(keyVal<0){
                      keyVal = this.ALPHABET.length() + keyVal;
                }
                
                char replaceVal = this.ALPHABET.charAt(keyVal);
                plainText += replaceVal;
           }
           return plainText;
     }
   
  
}
